package com.sinoparasoft.lilac.web;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sinoparasoft.lilac.model.Mail;
import com.sinoparasoft.lilac.service.MailSender;

@Controller
public class LilacController {	
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ModelAndView intro(Locale locale, Model model) {
		return new ModelAndView("introduction.tile");	
	}
	
	@RequestMapping(value = "/userguide/vpn", method = RequestMethod.GET)
	public ModelAndView vpn(Locale locale, Model model) {
		return new ModelAndView("vpn.tile");
	}
	
	@RequestMapping(value = "/userguide/ssh", method = RequestMethod.GET)
	public ModelAndView ssh(Locale locale, Model model) {
		return new ModelAndView("ssh.tile");
	}
	
	@RequestMapping(value = "/userguide/password", method = RequestMethod.GET)
	public ModelAndView password(Locale locale, Model model) {
		return new ModelAndView("password.tile");
	}
	
	@RequestMapping(value = "/userguide/job", method = RequestMethod.GET)
	public ModelAndView job(Locale locale, Model model) {
		return new ModelAndView("job.tile");
	}
	
	@RequestMapping(value = "/userguide/mpi", method = RequestMethod.GET)
	public ModelAndView mpi(Locale locale, Model model) {
		return new ModelAndView("mpi.tile");
	}
	
	@RequestMapping(value="/feedback", method = RequestMethod.GET)
	public ModelAndView feedback(Locale locale, Model model) {
		return new ModelAndView("feedback.tile");
	}
	
	@RequestMapping(value = "/feedback", method = RequestMethod.POST)
	public @ResponseBody String feedback(HttpServletRequest request, HttpServletResponse response) {
		String type = request.getParameter("type"); 
		String title = request.getParameter("title");
		String category = request.getParameter("category");
		String content = request.getParameter("content");
		String name = request.getParameter("name");
		
		Mail mail = new Mail("[" + type + "]" + "[" + category + "]" + "[" + name + "]" + "[" + title + "]", content);
		
		MailSender sender = new MailSender();
		sender.send(mail, false);
		
		return "ok";
	}
	
	@RequestMapping(value = "/work", method = RequestMethod.GET)
	public ModelAndView work(Locale locale, Model model) {
		return new ModelAndView("work.tile");
	}
	
	@RequestMapping(value = "/faq", method = RequestMethod.GET)
	public ModelAndView faq(Locale locale, Model model) {
		return new ModelAndView("faq.tile");
	}
	
	@RequestMapping(value = "/error/404", method = RequestMethod.GET)
	public ModelAndView error404(Locale locale, Model model) {
		return new ModelAndView("404.tile");
	}
}
